package factory.abstract1;

/**
 * Remarks:
 * Class name :Demo
 * Date :2023/2/17 09:58
 * Author:杨俊源
 */
public class Demo {
    public static void main(String[] args) {
        System.out.println("===================小米系列产品===================");
        //小米工厂
        XiaomiFactory xiaomiFactory = new XiaomiFactory();
        IphoneProduct iphoneProduct = xiaomiFactory.iphoneProduct();
        iphoneProduct.callup();
        iphoneProduct.sendSMS();

        IRouterProduce iRouterProduce = xiaomiFactory.irouterProduce();
        iRouterProduce.start();
        iRouterProduce.openWifi();
        iRouterProduce.setting();
        iRouterProduce.shutdown();

        System.out.println("===================华为系列产品===================");
        //小米工厂
        HuaWeiFactory huaWeiFactory = new HuaWeiFactory();
        IphoneProduct huawei = huaWeiFactory.iphoneProduct();
        huawei.callup();
        huawei.sendSMS();

        IRouterProduce huaweiRouter = huaWeiFactory.irouterProduce();
        huaweiRouter.start();
        huaweiRouter.openWifi();
        huaweiRouter.setting();
        huaweiRouter.shutdown();
    }
}

//抽象产品工程
interface IProductFactory{
    //生产手机
    IphoneProduct iphoneProduct();
    //生产路由器
    IRouterProduce irouterProduce();
}

//小米手机工厂
class XiaomiFactory implements IProductFactory{
    @Override
    public IphoneProduct iphoneProduct() {
        return new XiaoMiPhone();
    }

    @Override
    public IRouterProduce irouterProduce() {
        return new XiaomiRouter();
    }
}

class HuaWeiFactory implements IProductFactory{

    @Override
    public IphoneProduct iphoneProduct() {
        return new HuaweiPhone();
    }

    @Override
    public IRouterProduce irouterProduce() {
        return new HuaweiRouter();
    }
}


//手机
interface IphoneProduct{
    void start();
    void shutdown();
    void callup();
    void sendSMS();
}

//路由器
interface IRouterProduce{
    void start();
    void shutdown();
    void openWifi();
    void setting();
}

//小米手机
class XiaoMiPhone implements IphoneProduct{
    @Override
    public void start() {
        System.out.println("开启小米手机");
    }

    @Override
    public void shutdown() {
        System.out.println("关闭小米手机");
    }

    @Override
    public void callup() {
        System.out.println("小米手机打电话");
    }

    @Override
    public void sendSMS() {
        System.out.println("小米手机发短信");
    }
}

//华为手机
class HuaweiPhone implements IphoneProduct{
    @Override
    public void start() {
        System.out.println("开启华为手机");
    }

    @Override
    public void shutdown() {
        System.out.println("关闭华为手机");
    }

    @Override
    public void callup() {
        System.out.println("华为手机打电话");
    }

    @Override
    public void sendSMS() {
        System.out.println("华为手机发短信");
    }
}

//小米路由器
class XiaomiRouter implements IRouterProduce{
    @Override
    public void start() {
        System.out.println("启动小米路由器");
    }

    @Override
    public void shutdown() {
        System.out.println("关闭小米路由器");
    }

    @Override
    public void openWifi() {
        System.out.println("打开小米WiFi");
    }

    @Override
    public void setting() {
        System.out.println("设置小米路由器");
    }
}

//华为路由器
class HuaweiRouter implements IRouterProduce{
    @Override
    public void start() {
        System.out.println("启动华为路由器");
    }

    @Override
    public void shutdown() {
        System.out.println("关闭华为路由器");
    }

    @Override
    public void openWifi() {
        System.out.println("打开华为WiFi");
    }

    @Override
    public void setting() {
        System.out.println("设置华为路由器");
    }
}
